package com.zoo.buyor.websocket.adapter;

import com.zoo.buyor.user.domain.entity.User;
import com.zoo.buyor.websocket.domain.enums.WSRespTypeEnum;
import com.zoo.buyor.websocket.domain.vo.response.WSBaseResp;
import com.zoo.buyor.websocket.domain.vo.response.WSLoginSuccess;
import com.zoo.buyor.websocket.domain.vo.response.WSLoginUrl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.springframework.stereotype.Component;

@Component
public class  WebSocketAdapter {
    public static WSBaseResp<WSLoginUrl> buildWsBaseResp(WxMpQrCodeTicket wxMpQrCodeTicket){
        WSBaseResp<WSLoginUrl> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        wsBaseResp.setData(new WSLoginUrl(wxMpQrCodeTicket.getUrl()));
        return  wsBaseResp;
    }

    public static WSBaseResp<WSLoginSuccess> buildWSLoginResp(User user, String token) {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess build = WSLoginSuccess.builder()
                .uid(user.getId())
                .avatar(user.getAvatar())
                .token(token)
                .name(user.getName())
                .build();
        //.power(user.getPower())
        resp.setData(build);
        return resp;
    }
}
